package tiruvury.InterviewPrep.HelperClasses;

import java.util.Arrays;
import java.util.Comparator;

public class AnagramComparator implements Comparator<String>
{
	/*
	 * CODINGERROR: The Compare implementation should be PUBLIC. And compare
	 * should be lowercase.
	 */
	public int compare(String a, String b)
	{
		char[] aArray = a.toCharArray();
		char[] bArray = b.toCharArray();
		Arrays.sort(aArray);
		Arrays.sort(bArray);

		/*
		 * CODINGERROR: When converting char array to string, you must new up a
		 * new instance of String.
		 * String aNew = aArray.toString(); => WRONG
		 * String aNew = new String(aArray); => RIGHT
		 */
		String aNew = new String(aArray);
		String bNew = new String(bArray);

		/*
		 * CODINGERROR: Since you want to return a comparison output as an INT,
		 * use compareTo()
		 */
		return (aNew).compareTo(bNew);
	}
}
